home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 16.2 KB | 527 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UStructureInspectors.cp
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __USTRUCTUREINSPECTORS__
- #include "UStructureInspectors.h"
- #endif
-
- // MacApp
-
- #ifndef __UAPPLICATION__
- #include "UApplication.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
-
- //========================================================================================
- // Global Functions
- //========================================================================================
- static Boolean ListsMatch(TList* firstList,TList* secondList);
- static short GetDepth(TView* aView);
- static void FlattenTargetChain(TEventHandler* head, TList* theList);
-
- //========================================================================================
- // CLASS TIdler
- //========================================================================================
- #undef Inherited
- #define Inherited TEventHandler
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TIdler, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIdler constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TIdler::TIdler()
- {
- fHandler = NULL;
- } // TIdler::TIdler
-
- //----------------------------------------------------------------------------------------
- // TIdler destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TIdler::~TIdler()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TIdler::IIdler:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIdler::IIdler(TEventHandler* itsHandler)
- {
- this->IEventHandler(NULL);
-
- fHandler = itsHandler;
- this->SetIdleFreq(fHandler->GetIdleFreq());
- } // TIdler::IIdler
-
- //----------------------------------------------------------------------------------------
- // TIdler::DoIdle:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- Boolean TIdler::DoIdle(IdlePhase phase) // override
- {
- if (fHandler)
- return fHandler->DoIdle(phase);
- else
- return FALSE;
- } // TIdler::DoIdle
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // ListsMatch:
- //----------------------------------------------------------------------------------------
- Boolean ListsMatch(TList* firstList,TList* secondList)
- {
- if (firstList->GetSize() != secondList->GetSize())
- return FALSE;
- else
- {
- //return EqualBlocks(*((Handle) firstList), *((Handle) secondList),GetHandleSize((Handle) firstList));
- for (ArrayIndex i = 1; i <= firstList->GetSize(); i++)
- {
- if (firstList->At(i) != secondList->At(i))
- return FALSE;
- }
- return TRUE;
- }
- } // ListsMatch
-
-
- //========================================================================================
- // CLASS TObjectListView
- //========================================================================================
- #undef Inherited
- #define Inherited TTextListView
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TObjectListView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TObjectListView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TObjectListView::TObjectListView()
- {
- fAList = NULL;
- fBList = NULL;
- fDisplayedList = NULL;
- fIdler = NULL;
- } // TObjectListView::TObjectListView
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TObjectListView::DoPostCreate(TDocument* itsDocument)// override
- {
- Inherited::DoPostCreate(itsDocument);
-
- FailInfo fi;
-
- Try(fi)
- {
- fAList = NewList();
- fBList = NewList();
- fDisplayedList = fAList;
-
- TIdler* anIdler = new TIdler;
- anIdler->IIdler(this);
- fIdler = anIdler;
- fi.Success();
- }
- else
- {
- fAList = (TList*) FreeIfObject(fAList);
- fBList = (TList*) FreeIfObject(fBList);
- fIdler = (TIdler*) FreeIfObject(fIdler);
- fDisplayedList = NULL;
- fi.ReSignal();
- }
-
- } // TObjectListView::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TObjectListView::~TObjectListView() // Override
- {
- fAList = (TList*) FreeIfObject(fAList);
- fBList = (TList*) FreeIfObject(fBList);
- fIdler = (TIdler*) FreeIfObject(fIdler);
- } // TObjectListView::Free
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::BuildList:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TObjectListView::BuildList(TList* newList)
- {
- newList->DeleteAll();
- } // TObjectListView::BuildList
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::IsSynchronized:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- Boolean TObjectListView::IsSynchronized()
- {
- TList* theNewList;
- TList* theOldList;
-
- if (fDisplayedList == fAList)
- {
- theNewList = fBList;
- theOldList = fAList;
- }
- else
- {
- theNewList = fAList;
- theOldList = fBList;
- }
-
- this->BuildList(theNewList);
- return ListsMatch(theOldList,theNewList);
- } // TObjectListView::IsSynchronized
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::Synchronize:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TObjectListView::Synchronize(Boolean /* redraw */)
- {
- TList* theNewList;
- TList* theOldList;
-
- if (fDisplayedList == fAList)
- {
- theNewList = fBList;
- theOldList = fAList;
- }
- else
- {
- theNewList = fAList;
- theOldList = fBList;
- }
-
- this->BuildList(theNewList);
- if (!ListsMatch(theOldList,theNewList))
- {
- TObject* selectedObject = this->GetSelectedObject();
-
- if (theOldList->GetSize() != theNewList->GetSize())
- {
- this->DelItemLast(fNumOfRows);
- this->InsItemLast((short) theNewList->GetSize());
- }
- fDisplayedList = theNewList;
- if (selectedObject)
- this->SelectObject(selectedObject);
- this->ScrollSelectionIntoView(!kRedraw);
- this->ForceRedraw();
- }
- } // TObjectListView::Synchronize
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TObjectListView::Draw(const VRect& area) // Override
- {
- if (this->IsSynchronized())
- Inherited::Draw(area);
- // Otherwise, let next idle synchronize
- } // TObjectListView::Draw
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::DoIdle:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- Boolean TObjectListView::DoIdle(IdlePhase /*phase*/) // override
- {
- this->Synchronize(kRedraw);
- return FALSE;
- } // TObjectListView::DoIdle
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::Open:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TObjectListView::Open() // override
- {
- gApplication->InstallCohandler(fIdler,TRUE);
- Inherited::Open();
- } // TObjectListView::Open
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::Close:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TObjectListView::Close() // override
- {
- gApplication->InstallCohandler(fIdler,FALSE);
- Inherited::Close();
- } // TObjectListView::Close
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::GetSelectedObject:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TObject* TObjectListView::GetSelectedObject()
- {
- return this->GetNthObject(this->FirstSelectedItem());
- } // TObjectListView::GetSelectedObject
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::GetNthObject:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TObject* TObjectListView::GetNthObject(short n)
- {
- if (fDisplayedList && (n > 0) && (n <= fDisplayedList->GetSize()))
- return fDisplayedList->At(n);
- else
- return NULL;
- } // TObjectListView::GetNthObject
-
- //----------------------------------------------------------------------------------------
- // TObjectListView::SelectObject:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TObjectListView::SelectObject(TObject* anObject)
- {
- ArrayIndex index = fDisplayedList->GetIdentityItemNo(anObject);
- this->SelectItem((short) index,FALSE,FALSE,TRUE);
- } // TObjectListView::SelectObject
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // GetDepth:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- short GetDepth(TView* aView)
- {
- if (aView->fSuperView == NULL)
- return 0;
- else
- return 1 + GetDepth(aView->fSuperView);
- } // GetDepth
-
-
- //========================================================================================
- // CLASS TViewHierarchyView
- //========================================================================================
- #undef Inherited
- #define Inherited TObjectListView
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TViewHierarchyView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TViewHierarchyView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TViewHierarchyView::~TViewHierarchyView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TViewHierarchyView::BuildList:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TViewHierarchyView::BuildList(TList* newList) // Override
- {
- newList->DeleteAll();
- this->FlattenHierarchy(NULL,newList);
- } // TViewHierarchyView::BuildList
-
- //----------------------------------------------------------------------------------------
- // TViewHierarchyView::FlattenHierarchy:
- //----------------------------------------------------------------------------------------
-
- void TViewHierarchyView::FlattenHierarchy(TView* root, TList* theList)
- {
- if (root)
- {
- theList->InsertLast(root);
-
- CSubViewIterator iter(root);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- this->FlattenHierarchy(theSubView, theList);
- }
- }
- else
- {
- CWMgrIterator iter;
-
- for (WindowRef aWinPtr = iter.FirstWMgrWindow(); iter.More(); aWinPtr = iter.NextWMgrWindow())
- {
- TWindow * aWindow = gApplication->WMgrToWindow(aWinPtr);
- if (aWindow && (aWindow != this->GetWindow()))
- this->FlattenHierarchy(aWindow, theList);
- }
- }
- } // TViewHierarchyView::FlattenHierarchy
-
- //----------------------------------------------------------------------------------------
- // TViewHierarchyView::GetItemText:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TViewHierarchyView::GetItemText(short anItem,
- CStr255& aString)// override
- {
- if (anItem <= fDisplayedList->GetSize())
- {
- TView* theView = (TView*) this->GetNthObject(anItem);
-
- if (theView)
- {
- CStr255 indentString = "......................................................................................................................";
- indentString.Length() = GetDepth(theView) * 2;
-
- aString = indentString + theView->GetClassName() + " '" + CStr15(theView->fIdentifier) + "'";
- }
- else
- aString = "Error";
- }
- } // TViewHierarchyView::GetItemText
-
- //----------------------------------------------------------------------------------------
- // TViewHierarchyView::GetSelectedView:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TView* TViewHierarchyView::GetSelectedView()
- {
- return (TView*) this->GetSelectedObject();
- } // TViewHierarchyView::GetSelectedView
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // FlattenTargetChain:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void FlattenTargetChain(TEventHandler* head, TList* theList)
- {
- theList->InsertLast(head);
- if (head->fNextHandler)
- FlattenTargetChain(head->fNextHandler,theList);
- } // FlattenTargetChain
-
-
- //========================================================================================
- // CLASS TTargetChainView
- //========================================================================================
- #undef Inherited
- #define Inherited TObjectListView
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TTargetChainView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTargetChainView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TTargetChainView::~TTargetChainView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTargetChainView::BuildList:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TTargetChainView::BuildList(TList* newList) // Override
- {
- newList->DeleteAll();
- FlattenTargetChain(gApplication->GetTarget(),newList);
- } // TTargetChainView::BuildList
-
- //----------------------------------------------------------------------------------------
- // TTargetChainView::GetItemText:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TTargetChainView::GetItemText(short anItem,
- CStr255& aString)// override
- {
- if (anItem <= fDisplayedList->GetSize())
- {
- TEventHandler* theHandler = (TEventHandler*) this->GetNthObject(anItem);
-
- aString = theHandler ? CStr255(theHandler->GetClassName()) + " '" + CStr15(theHandler->fIdentifier) + "'" : CStr255("Error");
- }
- } // TTargetChainView::GetItemText
-
- //----------------------------------------------------------------------------------------
- // TTargetChainView::GetSelectedHandler:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TEventHandler* TTargetChainView::GetSelectedHandler()
- {
- return (TEventHandler*) this->GetSelectedObject();
- } // TTargetChainView::GetSelectedHandler
-
- //----------------------------------------------------------------------------------------
- // End of UStructureInspectors.cp
-
- #pragma segment Inline
-